// pages/guide_detail/guideDetail.js
import {
    gethdLIst
} from "../../api/home"
Page({

    /**
     * 页面的初始数据
     */
    data: {
        timer: null,
        playing: false,
        currentDuration: 0,
        currentDurationStr: '00:00',
        allDuration: 120,
        allDurationStr: '00:00'
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        console.log(options);
        this.setData({
            allDurationStr: this.setFormat(this.data.allDuration)
        });
        gethdLIst({}).then(res=>{
            console.log(res);
        })
    },
    //点击返回
    onClickLeft() {
        wx.navigateBack({
            delta: 1,
        })
    },
    // 触发标签选中
    handleActive(e) {
        console.log(e);
    },
    handlePlay() {
        this.setData({
            playing: !this.data.playing
        })
        if (this.data.playing) {
            this.data.timer = setInterval(() => {
                this.setData({
                    currentDuration: this.data.currentDuration + 1,
                    currentDurationStr: this.setFormat(this.data.currentDuration + 1) + ''
                })
            }, 1000);
            this.setData({
                timer: this.data.timer
            })
        } else {
            clearInterval(this.data.timer)
            this.setData({
                timer: null
            })
        }

    },
    // 处理时间
    setFormat(duration) {
        let min = parseInt(duration / 60);
        let sec = parseInt(duration % 60);
        if (min.toString().length == 1) {
            min = `0${min}`;
        }
        if (sec.toString().length == 1) {
            sec = `0${sec}`;
        }
        return `${min}:${sec}`
    },
    //进来触发请求
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})